package com.cxb;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SHA512Utils {

	private SHA512Utils() {
		throw new IllegalStateException("铁子，工具类就不要实例化了。");
	}

	/**
	 * 字符串 SHA 加密
	 */
	public static String SHA512(final String strText) {
		// 返回值
		String strResult = null;

		try {
			MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
			messageDigest.update(strText.getBytes());
			byte[] byteBuffer = messageDigest.digest();
			StringBuilder strHexString = new StringBuilder();
			for (int i = 0; i < byteBuffer.length; i++) {
				String hex = Integer.toHexString(0xff & byteBuffer[i]);
				if (hex.length() == 1) {
					strHexString.append('0');
				}
				strHexString.append(hex);
			}
			strResult = strHexString.toString();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return strResult;
	}
}